package com.atguigu.tacket;

class Client {
    private int number = 50;
    public synchronized void Tocket(){
        if (number>0){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "卖出第："+number +"张,正在卖："+(number--) +"张");
        }
    }

    public static void main(String[] args) {
        Client client = new Client();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <51 ; i++) {
                    client.Tocket();
                }
            }
        },"A").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <51 ; i++) {
                    client.Tocket();
                }
            }
        },"b").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <51 ; i++) {
                    client.Tocket();
                }
            }
        },"c").start();



    }
}
